/*function numRand() {

    var x = 9999; //上限

    var y = 1000; //下限

    var rand = parseInt(Math.random() * (x - y + 1) + y);

    return rand;

}*/
//从服务器获取接收游戏数据

/*function numRand(){
    $.ajax({
        type:'post',
        url:'/back/game.php?type=lhj',
        data:'aa=aa',
        //async:false,
        success: function (msg) {
            msg = JSON.parse(msg);
            console.log(typeof msg.num);
            return msg.num;
        }
    });
}*/

var u = 265;
var isBegin = false;
var lhjmsg;
function lhjStart() {
    var can = cango();
    if (can) {
        $('.btn').off();
        mc();
        if (isBegin) return false;

        isBegin = true;

        $(".num").css('backgroundPositionY', 0);

        $.ajax({
            type: 'post',
            url: '/back/game.php?type=lhj',
            data: {'userch':$('#useyaya').val(),'yaya':$('#num').val()},
            //async:false,
            success: function (msg) {
                if(msg == 0){
                    alert('数据异常');
                }else{
                    lhjmsg = JSON.parse(msg);
                    setTimeout("Dialog.init(lhjmsg.xiaoxi,3000);$('#ji_fen').val(lhjmsg.jifen);$('#add').click(addnum);$('#jian').click(jiannum);",16000);
                    var num_arr = (lhjmsg.num + '').split('');
                    $(".num").each(function (index) {

                        var _num = $(this);

                        setTimeout(function () {

                            _num.animate({

                                backgroundPositionY: (u * 60) - (u * num_arr[index])

                            }, {

                                duration: 6000 + index * 3000,

                                easing: "easeInOutCirc",

                                complete: function () {

                                    if (index == 3) isBegin = false;

                                }

                            });

                        }, index * 300);

                    });
                }
            }
        });
    }
}

function lhjer(){
    $('#add').off();
    $('#jian').off();
    lhjStart();
    setTimeout("$('.btn').click(lhjer);$('#add').click(addnum);$('#jian').click(jiannum);",16000);
}

$(function() {
    $('.btn').click(lhjer);
});